#ifndef TOUCH_CALIBRATION_H
#define TOUCH_CALIBRATION_H

#include <QDialog>

#include <QLabel>
#if QT_VERSION < 0X050000
#include <QWSPointerCalibrationData>
#include <QtGui/QHBoxLayout>
#include <QtGui/QSpacerItem>
#include <QWSServer>
#else
#include <QHBoxLayout>
#include <QSpacerItem>
#endif
#define MCGS_CALIBRATION_DRAWCROSS_TIMEOUT 20
#define MCGS_CALIBRATION_SCREEN_POINTS 	   20
#define MCGS_CALIBRATION_PROBE_SET         12

//zhaolunhan
class touch_calibration :QDialog  /*: public modal_base_dialog*/
{
    Q_OBJECT

public:
    explicit touch_calibration(QWidget* parent = 0);
    ~touch_calibration();
    int calibration_exec();
    int calibration_exec_without_clear();

protected:
    virtual void paintEvent(QPaintEvent*);
    virtual void mousePressEvent(QMouseEvent*);
    virtual void mouseMoveEvent(QMouseEvent*);
    virtual void mouseReleaseEvent(QMouseEvent*);
    virtual void accept();

private:
    void set_ui(QDialog* dlg);
    void calibration_confirm_ui(QPainter* painter);
    bool linear_coefficient_verify();

protected slots:
    void probe_calibration();
    void draw_cross();

private:
    QGridLayout* _grid_layout;

    QVBoxLayout* _v_layout;
    QHBoxLayout* _h_layout1;
    QHBoxLayout* _h_layout2;

    QSpacerItem* _h_spacer1;
    QSpacerItem* _h_spacer2;
    QSpacerItem* _h_spacer3;
    QSpacerItem* _h_spacer4;

    QSpacerItem* _v_spacer1;
    QSpacerItem* _v_spacer2;
    QSpacerItem* _v_spacer3;

    QLabel* _step1;
    QLabel* _step2;

    QWSPointerCalibrationData _former_data;
    QWSPointerCalibrationData _data;
    QPoint _other_screen_points[4][MCGS_CALIBRATION_SCREEN_POINTS];
    int _pressCount;
    QTimer* _press_timer;
    QTimer* _draw_timer;
    int _which;

    QPoint _average_array[MCGS_CALIBRATION_PROBE_SET];
    int _average_index;
    int _total_num;

    bool _calibration_ret;
};

#endif
